import { _decorator, Component, Node } from 'cc';
import { BaseComponent } from '../../Manager/UIManager/BaseComponent';
import { GAME_POP, GAME_SCENE, SOUND_TYPE } from '../../Data/GlobalData';
const { ccclass, property } = _decorator;

@ccclass('PopSet')
/**
 * 顶部设置层
 */
export class PopSet extends BaseComponent {

    //背景音乐开关层
    @property(Node)
    private MusicBtn: Node = null;

    //音效开关层
    @property(Node)
    private EffectBtn: Node = null;

    //返回首页按钮
    @property(Node)
    public GoLoginBtn: Node = null;

    //
    public Cb: Function = null;

    protected Init(): void {

    }

    protected OnShow(): void {
        this.GoLoginBtn.active = true;
        this.BtnShow(this.MusicBtn, app.audioManager.IsBg);
        this.BtnShow(this.EffectBtn, app.audioManager.IsEffect);
    }



    /**
     * 更新按钮显示
     */
    private BtnShow(_btn: Node, _isopen: boolean) {
        _btn.getChildByName('open').active = _isopen;
        _btn.getChildByName('close').active = !_isopen;
    }

    /**
     * 背景音乐点击
     */
    private MusicClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.audioManager.IsBg = !app.audioManager.IsBg;

        if (app.audioManager.IsBg) {
            app.audioManager.PlayBgSound();
        } else {
            app.audioManager.StopBgSound();
        }

        this.BtnShow(this.MusicBtn, app.audioManager.IsBg);
    }

    /**
     * 音效点击
     */
    private EffectClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.audioManager.IsEffect = !app.audioManager.IsEffect;
        this.BtnShow(this.EffectBtn, app.audioManager.IsEffect);
    }

    /**
     * 震动点击
     */
    private ShakeClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.audioManager.IsShake = !app.audioManager.IsShake;
    }

    /**
     * 点击关闭按钮
     */
    private CloseClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.popManager.HidePop(GAME_POP.PopSet)
        this.Cb && this.Cb();
    }

    /**
     * 点击回到首页
     */
    private GoLoginClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.popManager.HidePop(GAME_POP.PopSet);
        app.uiManager.ShowUI(GAME_SCENE.LoginScene);
    }

}


